import storage from "@/utils/storage"
//权限检查方法
function checkPermission(value: any) {
  let isExist = false
  const buttonArr = storage.get("userinfo").btnrole
  //判断是否按钮有权限
  if (buttonArr.includes(value)) {
    isExist = true
  }
  return isExist
}
export const v = [
  {
    name: "highlight",
    directive: {
      created(el: any, binding: any, vnode: any) {},
      beforeMount(el: any, binding: any, vnode: any) {
        // el.style.background = binding.value
        el.style.color = binding.value
      },
      mounted() {},
      beforeUpdate(a: any, b: any, c: any, prevNode: any) {
        //! 第四个参数 prevNode 只在beforeUpdate和updated才有！
        a.style.background = b.value
      },
      updated() {},
      beforeUnmount() {
        // 当指令绑定的元素 的父组件销毁前调用。  <简单讲，指令元素的父组件销毁前调用>
      },
      unmounted() {}, // 当指令与元素解除绑定且父组件已销毁时调用。
    },
  },
  {
    name: "hasPermiss",
    directive: {
      created(el: any, binding: any, vnode: any) {},
      async beforeMount(el: any, binding: any, vnode: any) {
        await nextTick()
        const res = checkPermission(binding.value)
        !res && el.parentNode.removeChild(el)
      },
      mounted() {},
      beforeUpdate(a: any, b: any, c: any, prevNode: any) {
        //! 第四个参数 prevNode 只在beforeUpdate和updated才有！
        // a.style.background = b.value
      },
      updated() {},
      beforeUnmount() {
        // 当指令绑定的元素 的父组件销毁前调用。  <简单讲，指令元素的父组件销毁前调用>
      },
      unmounted() {}, // 当指令与元素解除绑定且父组件已销毁时调用。
    },
  },
  {
    name: "striping",
    directive: {
      created(el: any, binding: any, vnode: any) {},
      beforeMount(el: any) {
        const stripLeft = document.createElement("div")
        const stripRight = document.createElement("div")
        stripLeft.style.position = "absolute"
        stripLeft.style.width = "9.89vw"
        stripLeft.style.height = "1px"
        stripLeft.style.backgroundColor = "#737e91"
        stripLeft.style.left = "35%"
        stripLeft.style.top = "50%"
        stripLeft.style.transform = "translate(-35%, -50%)"
        stripRight.style.position = "absolute"
        stripRight.style.width = "9.89vw"
        stripRight.style.height = "1px"
        stripRight.style.backgroundColor = "#737e91"
        stripRight.style.right = "35%"
        stripRight.style.top = "50%"
        stripRight.style.transform = "translate(35%, -50%)"
        el.appendChild(stripLeft)
        el.appendChild(stripRight)
      },
      mounted() {},
      beforeUpdate(a: any, b: any, c: any, prevNode: any) {
        //! 第四个参数 prevNode 只在beforeUpdate和updated才有！
        // a.style.background = b.value
      },
      updated() {},
      beforeUnmount() {
        // 当指令绑定的元素 的父组件销毁前调用。  <简单讲，指令元素的父组件销毁前调用>
      },
      unmounted() {}, // 当指令与元素解除绑定且父组件已销毁时调用。
    },
  },
]
